<?php

require_once ROOT_PATH . '/lib/models/surveys/Questions.php';
require_once ROOT_PATH . '/lib/models/surveys/Options.php';

class EXTRACTOR_Questions {

	public function parseAddData($postArr) {
		
		// Extract dates
		//$array=new array();		
		$question = New Questions();
		
		//$question->setId($maxId+1);
		$question->setText($postArr['txtQuestion']);
		$question->setSurveyId($postArr['surveyid']);
		$question->setAnswerType($postArr['answerType']);
		$array['question']=$question;
		
		if($postArr['answerType']== 2 ||$postArr['answerType']== 3)
		{	
			$j=0;
			for($i=1;$i<=5;$i++){
				if((isset($postArr['txtOption'.$i])&& $postArr['txtOption'.$i]!='') ){
					$option = New Options();
					
					$option->setText($postArr['txtOption'.$i]);
					//$option->setValue($postArr['txtValue'.$i]);
					$optionArr[$j]=	$option;
					$j++;
				}
			}
		}
		if(isset($optionArr)&& count($optionArr)>0)
			$array['options']=$optionArr;
		else 
			$array['options']=null;
	
		return $array;
	}
	
	public function parseEditData($postArr) {
		
		// Extract dates
		//$array=new array();		
		$question = Questions::getQuestionById($postArr['txtId']);
		
		//$question->setId($maxId+1);
		$question->setText($postArr['txtQuestion']);	
		return $question;
	}
}
?>